package download.itydl.com.sinlethread.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * use for 数据库操作类
 * 数据库里面存储的是当前线程已经下载的信息（可类比临时文件）  对应下载线程 ThreadInfo 建表对应ThreadInfo类
 *
 * @author howard
 */
public class MyDBHelper extends SQLiteOpenHelper {

    private static final String DB_NAME = "download.db";

    private static final String SQL_CREATE = "create table thread_info(" +
            "_id integer primary key autoincrement," +
            "thread_id integer," +
            "url text," +
            "start long," +
            "end long," +
            "finished long)";

    private static final String SQL_DROP = "drop table if exists thread_info";

    private static final int VERSION = 1;


    public MyDBHelper(Context context) {
        super(context, DB_NAME, null, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(SQL_CREATE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(SQL_DROP);
        db.execSQL(SQL_CREATE);
    }
}